﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.EzAppApi.Utility.EzDeskAppApi;

namespace EzDesk.EzAppApi.Utility
{
    /// <summary>
    ///  没有实现Mock的方法则调用WebService
    /// </summary>
    public class Mock_EzApiClient:IEzApiClient
    {
        public static Guid GetMockUserId(string name)
        {
            return innerUserProfileStorage.Where(u => u.Name == name).SingleOrDefault().Id;
        }


        public static SimpleUser GetMockUser(string p)
        {
            return Mock_EzApiClient.ToSimpleUser(innerUserProfileStorage.Where(u => u.Name == p).SingleOrDefault());
        }


        private static SimpleUser ToSimpleUser(UserProfile profile)
        {
            return new SimpleUser()
            {
                Id = profile.Id,
                Dept = Mock_EzApiClient.GetDept(profile.DeptId.GetValueOrDefault()),
                Name = profile.Name,
                UserName = profile.UserName,
            };
        }

        private static Dept GetDept(Guid id)
        {
            return innerDeptStorage.Where(p => p.Id == id).SingleOrDefault();
        }

        #region [ Mock Data ]
        static List<UserProfile> innerUserProfileStorage = new List<UserProfile>()
        {
            new UserProfile(){Id=new Guid("CCCC1AA9-C810-4C5C-855F-1005567DC001"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="雷卓扬", UserName="lzy", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("CEAC7C91-519B-4824-BDBA-133DFAA0D0A4"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="解新鹏", UserName="xxp", PositionId=new Guid("D77A69BA-C92D-43B3-89DB-8E2DC7DDE248"),},
            new UserProfile(){Id=new Guid("52896714-DEF1-4ECE-9A13-21524EB1A0C9"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="袁兰珍", UserName="YLZ", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("EC1A3FA0-4106-48F9-BEB2-2785BC2AC1AE"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="逄丽娟", UserName="plj", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("076FE1E1-6D78-459C-B7A8-2825DEFBEC1A"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="潘雄华", UserName="PXH", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("FD037326-7C2C-48A1-A3BA-2ED0CF101CCB"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="冯乃乙", UserName="FNY", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("CE36C495-38CC-4B7E-875E-364FF8E087B5"), DeptId=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), Name="卢春叶", UserName="lcy", PositionId=new Guid("8057C1EC-742C-4E90-9140-7CF202ED2C0C"),},
            new UserProfile(){Id=new Guid("55101D8A-DD23-4317-8AEB-3E3E4B8E5DDB"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="孙华晓", UserName="SHX", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("877C3323-17A7-42D1-9D75-402FFC894E63"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="Karin", UserName="Karin", PositionId=new Guid("EE55C782-3630-476E-9042-CB38D92E5685"),},
            new UserProfile(){Id=new Guid("552E3038-5E63-43B8-9E35-51223864521F"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="李燕珍", UserName="lyz", PositionId=new Guid("CA80C944-B9A3-45AD-ABAD-E4C39A0E3E77"),},
            new UserProfile(){Id=new Guid("9732775F-029E-4466-BD7C-5546F637EDA2"), DeptId=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), Name="蔡靖", UserName="cj", PositionId=new Guid("8057C1EC-742C-4E90-9140-7CF202ED2C0C"),},
            new UserProfile(){Id=new Guid("A50F8E47-4583-4B32-B416-591EB99ED439"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="郭征宇", UserName="gzy", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("BD62F1AC-8FA4-4E32-9CB0-6C5FE6151B83"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="杨聪聪", UserName="ycc", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("38C5FE46-62C2-4D24-A67D-70260F648162"), DeptId=new Guid("B9F045BD-959E-46E5-8801-64383DD776E2"), Name="贺旭华", UserName="hxh", PositionId=new Guid("FA88ECE2-B3A5-418D-9E68-3C29E7A51D8C"),},
            new UserProfile(){Id=new Guid("0FC4B7EB-6710-45E7-95A0-76A2E9457FEB"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="侯双建", UserName="hsj", PositionId=new Guid("D77A69BA-C92D-43B3-89DB-8E2DC7DDE248"),},
            new UserProfile(){Id=new Guid("65245628-8077-4F59-98AF-7B49829DCDC4"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="伏广庆", UserName="fgq", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("C0062083-ABF6-4305-A364-8760D83CA7B2"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="林泉", UserName="lq", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("A8E6BB69-23A2-4C1B-BC49-88C4675D9C0F"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="武敏", UserName="wm", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("EB431A22-EF3B-4A3F-BF7F-8DA53374446B"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="陈黎", UserName="CL", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("805B0F60-4DB0-49E8-BDF3-8EE310D0E59E"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="吴昊", UserName="wh", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("7046FE41-8974-4947-8D5E-9859CE199CD9"), DeptId=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), Name="韩晓华", UserName="韩晓华", PositionId=new Guid("8057C1EC-742C-4E90-9140-7CF202ED2C0C"),},
            new UserProfile(){Id=new Guid("365B471E-4074-4BAA-B33C-A2E0661E2095"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="刘思亭", UserName="lst", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("8ED5D3F7-C3CD-4752-99B7-A77693E1FE19"), DeptId=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), Name="沈培元", UserName="tank", PositionId=new Guid("77F0165A-7455-464E-95C0-3B6284981801"),},
            new UserProfile(){Id=new Guid("E58E58D6-5CEC-4857-B913-A9D706CF08DB"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="顾弘毅", UserName="ghy", PositionId=new Guid("EA8A615C-DE61-494B-9AB9-8A2E653F6FBD"),},
            new UserProfile(){Id=new Guid("8A3AE142-E5AC-4697-B72D-AB6EAB91E1CB"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="冯力", UserName="fl", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("9D638065-74C2-4169-B04A-BC904B7F6C87"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="胡海江", UserName="hhj", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("B2BF1810-7D50-477B-A41E-BEB08E99C8F1"), DeptId=new Guid("69C0F046-24D0-4D07-805E-EEDFC65AA043"), Name="徐剑", UserName="xj", PositionId=new Guid("C9106717-76F3-4781-A2AB-690F4D4E133A"),},
            new UserProfile(){Id=new Guid("329487E6-5994-4D6B-8DD6-BF249F3F3BEC"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="史重洁", UserName="scj", PositionId=new Guid("0E005E63-91BC-415C-B509-BAF43AB1A951"),},
            new UserProfile(){Id=new Guid("B47D38F2-C4D7-47F8-B344-D4D077525F52"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="陆侃翔", UserName="LKX", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("0C9D7C0C-04A5-4AE2-97A1-D7BBC38F5C66"), DeptId=new Guid("D69BA3E5-74B9-4650-9CDC-124392646B78"), Name="杨裕欣", UserName="yuxin", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("19F1C421-280F-4935-9980-E469175461C2"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="龚伟", UserName="gw", PositionId=new Guid("CA80C944-B9A3-45AD-ABAD-E4C39A0E3E77"),},
            new UserProfile(){Id=new Guid("80B71631-E0BA-4F87-B942-E48FA589D45B"), DeptId=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), Name="卫芸飞", UserName="wyf", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("C8493B9E-60EA-497A-82C6-E588BA7D8854"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="施东升", UserName="SDS", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("B99A541F-774F-4DF5-833C-EDD8DB617752"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="徐舟", UserName="xz", PositionId=new Guid("C9106717-76F3-4781-A2AB-690F4D4E133A"),},
            new UserProfile(){Id=new Guid("F5172642-9C5D-46C9-AD61-F8DA633290A1"), DeptId=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), Name="胡珺", UserName="hujun", PositionId=new Guid("EA8A615C-DE61-494B-9AB9-8A2E653F6FBD"),},
            new UserProfile(){Id=new Guid("AECB4585-8BA7-4F51-95DD-F9D4DEB4499A"), DeptId=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), Name="汪道平", UserName="wdp", PositionId=new Guid("D8951B57-1D46-410C-BA1F-5ADF1F7E60FB"),},
            new UserProfile(){Id=new Guid("7F386231-6B3F-4C90-A6EB-FE3C1483AF41"), DeptId=new Guid("B9F045BD-959E-46E5-8801-64383DD776E2"), Name="高欣铭", UserName="gxm", PositionId=new Guid("6FB850D8-161C-49EA-8A38-086D3C64D4B9"),},
        };

        static List<Dept> innerDeptStorage = new List<Dept>()
        {
            new Dept(){Id=new Guid("D69BA3E5-74B9-4650-9CDC-124392646B78"), DeptName = "软件工程部", GroupId = new Guid("F76F6EB7-DDEB-4D0D-9379-F2ECD2793EC5")},
            new Dept(){Id=new Guid("EDF7C6B0-BF96-4B97-A337-4CF7B37CD8A1"), DeptName = "方案部", GroupId = new Guid("5FCBDCED-5D39-490A-887B-C6992A635A1C")},
            new Dept(){Id=new Guid("B9F045BD-959E-46E5-8801-64383DD776E2"), DeptName = "总经理室", GroupId = new Guid("E687654C-85E3-4A21-B59C-418E147B84B2")},
            new Dept(){Id=new Guid("4A66C45D-0067-412E-8BDE-9BFD25A16B75"), DeptName = "行政部", GroupId = new Guid("4801B816-095A-4E6C-8B39-580F48D02D8E")},
            new Dept(){Id=new Guid("69C0F046-24D0-4D07-805E-EEDFC65AA043"), DeptName = "市场部", GroupId = new Guid("12576646-D198-4A0D-938C-C119DABDAE90")},
            new Dept(){Id=new Guid("4F1D8A14-A3EA-4396-9A7F-F9EE9F3C3A74"), DeptName = "施工图部", GroupId = new Guid("EFC27285-83F5-4A9A-8DED-E3C6DF7D1459")},
        };
        

        #endregion 
        public IList<Dept> GetAllDepts()
        {
            throw new NotImplementedException();
        }

        public IList<Group> GetAllSystemGroups()
        {
            throw new NotImplementedException();
        }

        public IList<SimpleUser> GetAllUsersByMemberString(string memberString)
        {
            throw new NotImplementedException();
        }

        public IDictionary<Guid, string> GetChildrenByMemberString(string memberString)
        {
            throw new NotImplementedException();
        }

        public Dept GetDeptById(Guid id)
        {
            return innerDeptStorage.Where(p => p.Id == id).SingleOrDefault();
        }

        public Group GetGroupById(Guid groupId)
        {
            throw new NotImplementedException();
        }

        public Group GetGroupByMemberstring(string memberstring)
        {
            throw new NotImplementedException();
        }

        public IList<Group> GetGroups(string groupIdStrs)
        {
            throw new NotImplementedException();
        }

        public SimpleUser GetSimpleUserById(Guid userId)
        {
            return ToSimpleUser(innerUserProfileStorage.Where(p => p.Id == userId).SingleOrDefault());
        }

        public IList<SimpleUser> GetSimpleUserInfos(string memberstring)
        {
            // todo: 不支持memberstring中包含groupId
            if (memberstring.Contains("|"))
            {
                throw new Exception("Mock暂时不支持GroupId");
            }

            List<SimpleUser> result = new List<SimpleUser>();
            if (memberstring == "everyone")
            {
                foreach (var user in innerUserProfileStorage)
                {
                    result.Add(ToSimpleUser(user));
                }
            }
            else
            {
                var userIds = memberstring.Split(',');
                foreach (var userId in userIds)
                {
                    result.Add(GetSimpleUserById(new Guid(userId)));
                }
            }
            return result;
        }

        public UserProfile GetUserProfileById(Guid userId)
        {
            throw new NotImplementedException();
        }

        public Guid SendFeed(string feedTypeStr, Guid templateId, Guid? senderId, string feedData, string memberString, bool sendToSelf)
        {
            throw new NotImplementedException();
        }

        public void SetFeedIsAvailable(Guid feedId, string memberString, bool isAvailable)
        {
            throw new NotImplementedException();
        }

        public void SetFeedsIsAvailable(string feedIdStrs, string memberstring, bool isAvailable)
        {
            throw new NotImplementedException();
        }

        public void UpdateFeedData(Guid updateFeedId, string newFeedData)
        {
            throw new NotImplementedException();
        }

        public void UpdateFeedsData(string feedIdsStr, string updateDataStr)
        {
            throw new NotImplementedException();
        }

        public void UpdatePersonalFeedData(Guid feedId, string memberstring, string feedDataEx)
        {
            throw new NotImplementedException();
        }


    }

}
